define(function(require, exports, module) {
	/***<pre>
	 * 下拉选择器
	 * config={
	 * 		id:'',
	 * 		title:'',
	 * 		width:'',
	 * 		type:{'type':'label'},
	 * 		data:{type:'',item:[{key:'',value,''}]},
	 * 		onSure:function(selectedKey){};
	 * }
	 * api:
	 * show(data,selectedKey)
	 * data:{type:'',item:[{key:'',value,''}
	 * </pre>*/
	var ModalDropdown=function(setting){
		this.setting={
			data:{}
		};
		$.extend(true,this.setting,setting);
		this.id=this.setting.id;
		this.data=this.setting.data;
		this.init();
	};
	
	ModalDropdown.prototype={
		show:function(data,selectedKey){
			this.clean();
			this.data=data;
			this.selectedKey=selectedKey;
			this.fill();
			this.$id.modal('show');
		},
		init:function(){
			this.render();
			this.bind();
		},
		render:function(){
			var html=[];
			html.push('<div class="modal fade ModalDropdown" id="'+this.id+'" tabindex="-1" role="dialog" aria-labelledby="ModalDropdown-'+this.id+'-Label"> ');
			html.push('   <div class="modal-dialog" role="document" style="width:'+this.setting.width+'"> ');
			html.push('     <div class="modal-content"> ');
			html.push('       <div class="modal-header"> ');
			html.push('         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> ');
			html.push('         <h4 class="modal-title" id="ModalDropdown-'+this.id+'-Label">'+this.setting.title+'</h4> ');
			html.push('       </div> ');
			html.push('       <div class="modal-body" > ');
			html.push('	       <form class="form-horizontal" role="form"><div class="form-group ">');
			html.push('       		<label for="ModalDropdown-'+this.id+'-select" class="col-xs-3 control-label">资源</label>');
			html.push('       		<div class="col-xs-9">');
			html.push('       			<select class="form-control" id="ModalDropdown-'+this.id+'-select"><option class="null" value="">请选择</option></select>');
			html.push('       </div></div></form>');
			html.push('       </div> ');
			html.push('       <div class="modal-footer" style="margin:0px;padding:10px 20px;"> ');
			html.push('         <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> ');
			html.push('         <button type="button" class="btn btn-primary btnSure">确定</button> ');
			html.push('       </div> ');
			html.push('     </div> ');
			html.push('   </div> ');
			html.push(' </div> ');
			this.$id=$(html.join(''));
			this.$select=this.$id.find('#ModalDropdown-'+this.id+'-select');
			this.$label=this.$id.find('.control-label');
		},
		bind:function(){
			var that=this;
			$('.btnSure',this.$id).on('click',function(){
				that.setting.onSure&&that.setting.onSure(that.$select.val());
				that.$id.modal('hide');
			});
		},
		clean:function(){
			this.$label.html('');
			this.$select.find('option[class!=null]').remove();
		},
		fill:function(){
			this.$label.html(this.setting.type[this.data.type]);
			var html=[],that=this;
			$.each(this.data.item,function(){
				html.push('<option '+(that.selectedKey==this.key?'selected':'')+' value='+this.key+'>'+this.value+'</option>');
			});
			this.$select.append(html.join(''));
		}
	};
	
	window['ModalDropdown']=ModalDropdown;
});